<?php
namespace app\admin\model;
use think\Model;
class Article extends Model
{
	// 获取文章详情
	public function detail($id)
	{
		$article = \think\facade\Db::name('article')->where(['id' => $id])->find();
		if (empty($article)) {
			return $this->error('文章不存在');
		}
		$keywrod_array = \think\facade\Db::name('ArticleKeywords')
			->field('i.aid,i.keywords_id,k.title')
			->alias('i')
			->join('keywords k', 'k.id = i.keywords_id', 'LEFT')
			->order('i.create_time asc')
			->where(array('i.aid' => $id, 'k.status' => 1))
			->select()->toArray();

		$article['keyword_ids'] = implode(",", array_column($keywrod_array, 'keywords_id'));
		$article['keyword_names'] = implode(',', array_column($keywrod_array, 'title'));
		return $article;
	}
}